<?php
class CLIST implements IDataType, Iterator {
	private $_position;
	private $_array;
	
	/**
	 * <h2>构造函数</h2>
	 * <p>初始化内部数据结构</p>
	 */
	public function __construct() {
		$this->_position = 0;
		$this->_array = array ();
	}
	
	/**
	 * <h2>给List中添加一个元素</h2>
	 *
	 * @param $mixed $e        	
	 * @return void
	 */
	public function append($e) {
		$this->_array [] = $e;
	}
	
	/**
	 * <h2>返回当前的元素</h2>
	 *
	 * @return mixed
	 * @see Iterator::current()
	 */
	public function current() {
		return $this->_array [$this->_position];
	}
	
	/**
	 * <h2>LIST内部指针指向下一个元素</h2>
	 *
	 * @return void
	 * @see Iterator::next()
	 */
	public function next() {
		++ $this->_position;
	}
	
	/**
	 * <h2>返回当前元素的下标</h2>
	 *
	 * @return scalar
	 *
	 * @see Iterator::key()
	 */
	public function key() {
		return $this->_position;
	}
	
	/**
	 * <h2>检查当前指针指向的元素是否有效</h2>
	 *
	 * @return bool
	 * @see Iterator::valid()
	 */
	public function valid() {
		return isset ( $this->_array [$this->_position] );
	}
	
	/**
	 * <h2>重置内部指针</h2>
	 *
	 * @return void
	 * @see Iterator::rewind()
	 */
	public function rewind() {
		$this->_position = 0;
	}
}